/**
 * @(#)ApkConfigController.java 2017年03月1日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseMapUtils;
import org.jsbd.boss.domian.EmailGroupBean;
import org.jsbd.boss.domian.EmailGroupRef;
import org.jsbd.boss.service.IEmailGroupService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/emailGroup")
public class EmailGroupController{

	private static final Logger LOGGER=LoggerFactory.getLogger(EmailGroupController.class);
	
	@Autowired
	private IEmailGroupService emailGroupService;

	/**
	 * 列表页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "listModel")
	public String showEmailGroupList(Model model) throws Exception {
		return "/emailGroup/emailGroupList";
	}

	@RequestMapping(value = "saveEmailGroup")
	@ResponseBody
	public Object saveEmailGroup(EmailGroupBean emailGroup){
		emailGroupService.saveEmailGroup(emailGroup);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "updateEmailGroup")
	@ResponseBody
	public Object updateEmailGroup(EmailGroupBean emailGroup){
		if (emailGroup.getId() == null) {
			return ResponseMapUtils.responseFail("参数缺失，请确认参数再提交");
		}
		
		EmailGroupBean condition=new EmailGroupBean();
		condition.setId(emailGroup.getId());
		EmailGroupBean temp=emailGroupService.getEmailGroup(condition);
		if(temp==null){
			return ResponseMapUtils.responseFail("记录未找到,请重试");
		}
		
		emailGroupService.updateEmailGroup(emailGroup);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "getEmailGroup")
	@ResponseBody
	public EmailGroupBean getEmailGroup(EmailGroupBean emailGroup) throws Exception {
		return emailGroupService.getEmailGroup(emailGroup);
	}

	@RequestMapping(value = "getEmailGroupList")
	@ResponseBody
	public List<EmailGroupBean> getEmailGroupList(EmailGroupBean emailGroup) throws Exception {
		return emailGroupService.getEmailGroupList(emailGroup);
	}

	@RequestMapping(value = "getEmailGroupListPage")
	@ResponseBody
	public Map<String, Object> getEmailGroupListPage(DataGridModel page, EmailGroupBean emailGroup) throws Exception {
		return emailGroupService.getEmailGroupListPage(page, emailGroup);
	}
	
	@RequestMapping(value = "deleteEmailGroup")
	@ResponseBody
	public Map<String, Object> deleteEmailGroup(EmailGroupBean emailGroup) throws Exception {
		emailGroupService.deleteEmailGroup(emailGroup);
		return ResponseMapUtils.responseSuccess();
	}
	
	@RequestMapping(value = "getOutEmailListPage")
	@ResponseBody
	public Map<String, Object> getOutEmailListPage(DataGridModel page, EmailGroupRef emailGroupRef) throws Exception {
		return emailGroupService.getOutEmailListPage(page, emailGroupRef);
	}
	
	@RequestMapping(value = "getInEmailListPage")
	@ResponseBody
	public Map<String, Object> getInEmailListPage(DataGridModel page, EmailGroupRef emailGroupRef) throws Exception {
		return emailGroupService.getInEmailListPage(page, emailGroupRef);
	}

	@RequestMapping(value = "saveEmailGroupRef")
	@ResponseBody
	public Map<String, Object> saveEmailGroupRef(EmailGroupRef emailGroupRef) {
		emailGroupService.saveEmailGroupRef(emailGroupRef);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "deleteEmailGroupRef")
	@ResponseBody
	public Map<String, Object> deleteEmailGroupRef(EmailGroupRef emailGroupRef) {
		emailGroupService.deleteEmailGroupRef(emailGroupRef);
		return ResponseMapUtils.responseSuccess(); 
	}
	
}
